unit fProjectView;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, dxSkinCaramel, dxSkinOffice2010Silver, dxSkinSeven,
  dxSkinscxPCPainter, cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, dxLayoutControl, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView, cxClasses,
  cxGridCustomView, cxGrid, cxPC, StdCtrls, RzLabel, RzDBLbl,
  dxSkinsdxBarPainter, dxBar, dImages, ComCtrls, cxContainer, cxListView;

type
  TfmProjectView = class(TForm)
    lcMain: TdxLayoutControl;
    lcgRoot: TdxLayoutGroup;
    lcgBaseInfoNormal: TdxLayoutGroup;
    lcgBaseInfoLeft: TdxLayoutGroup;
    lcgBaseInfoMiddle: TdxLayoutGroup;
    lcgBaseInfoRight: TdxLayoutGroup;
    lcgBaseInfoLast: TdxLayoutGroup;
    lcgDetails: TdxLayoutGroup;
    lcgFactoryInquire: TdxLayoutGroup;
    bmBrowser: TdxBarManager;
    BarMain: TdxBar;
    bbtnNew: TdxBarButton;
    bbtnEdit: TdxBarButton;
    bbtnRefresh: TdxBarButton;
    lcMainGroup1: TdxLayoutGroup;
    lvTrace: TcxListView;
    lcMainItem9: TdxLayoutItem;
    lvFactoryInquire: TcxListView;
    lcMainItem1: TdxLayoutItem;
    lvQuotation: TcxListView;
    lcMainItem2: TdxLayoutItem;
    lcMainGroup2: TdxLayoutGroup;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  procedure OnListViewDblClick(Sender: TObject);    

  public
    { Public declarations }
    FProjectId: string;
  end;

var
  fmProjectView: TfmProjectView;

implementation

uses
  uPublic, tools, fClientDataModule, uRelatedTools;

{$R *.dfm}

procedure TfmProjectView.FormShow(Sender: TObject);
var
  item: TListItem;
begin
  OpenPublicQuery('select dfi_no,dfi_date,dfi_fsimpname,dfi_staff,dfi_state,dfi_tracestate,dfi_tracedate from d_factoryinquire where dfi_projectid=' + QuotedStr(FProjectId));
  with ClientDataModule do
  begin
    tblDynamic.First;

    while not tblDynamic.EOF do
    begin

      item := lvFactoryInquire.Items.Add;
      item.Caption := tblDynamic.FieldByName('dfi_no').AsString;
      item.SubItems.Add(tblDynamic.FieldByName('dfi_date').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dfi_fsimpname').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dfi_staff').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dfi_state').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dfi_tracestate').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dfi_tracedate').AsString);

      tblDynamic.Next;
    end;
  end;

  
  OpenPublicQuery('select dps_state,dps_date,dps_remark from d_projectstate where dps_pid=' + QuotedStr(FProjectId));
  with ClientDataModule do
  begin
    tblDynamic.First;

    while not tblDynamic.EOF do
    begin
      item := lvTrace.Items.Add;
      item.Caption := tblDynamic.FieldByName('dps_state').AsString;
      item.SubItems.Add(tblDynamic.FieldByName('dps_date').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dps_remark').AsString);

      tblDynamic.Next;
    end;
  end;

  OpenPublicQuery('select dq_no,dq_date,dq_csimpname,dq_amt,dq_state,dq_versionno,dq_versiondesc from d_quotation where dq_projectid=' + QuotedStr(FProjectId));
  with ClientDataModule do
  begin
    tblDynamic.First;

    while not tblDynamic.EOF do
    begin
      item := lvQuotation.Items.Add;
      item.Caption := tblDynamic.FieldByName('dq_no').AsString;
      item.SubItems.Add(tblDynamic.FieldByName('dq_date').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dq_csimpname').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dq_amt').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dq_state').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dq_versionno').AsString);
      item.SubItems.Add(tblDynamic.FieldByName('dq_versiondesc').AsString);                        

      tblDynamic.Next;
    end;
  end; 

  lvFactoryInquire.OnDblClick := OnListViewDblClick;
  lvQuotation.OnDblClick := OnListViewDblClick;


end;

procedure TfmProjectView.OnListViewDblClick(Sender: TObject);
var
  itemdata: PBillData;
  listview: TcxListView;
begin
  listview := TcxListView(Sender);
  if listview.Selected = nil then Exit;

  itemdata := PBillData(listview.Selected.Data);
  ShowInfoWindowFromType(itemdata^.rType , itemdata^.rId);
  
  
end;

end.
